package com.hanbit.eatery.service.impl;

import com.hanbit.eatery.service.Eatery;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.hanbit.eatery.service.EateryService;

import java.util.HashMap;
import java.util.List;

@Repository("EateryServiceImpl")
public class EateryServiceImpl implements EateryService {
	
	@Autowired
	private SqlSessionTemplate sessionTemplate;

    @Override
    @Transactional
    public int insertEatery(Eatery eatery) {
        return sessionTemplate.getMapper(EateryMapper.class).insertEatery(eatery);
    }

    @Override
    public int maxNum() {
        return sessionTemplate.getMapper(EateryMapper.class).maxNum();
    }

    @Override
    public List<Eatery> getEateryList(int start, int end) {
    	HashMap<String, Integer> map=new HashMap<String, Integer>();
		map.put("start", start);
		map.put("end", end);
		return sessionTemplate
			.getMapper(EateryMapper.class).getEateryList(map);
	}

    @Override
    public int getEateryCount() {
        return sessionTemplate
    			.getMapper(EateryMapper.class).getEateryCount();
    }

    @Override
    public int updateEatery(Eatery eatery) {
        return sessionTemplate
                .getMapper(EateryMapper.class).updateEatery(eatery);
    }

    @Override
    public int deleteEatery(int eNum) {
        return sessionTemplate
                .getMapper(EateryMapper.class).deleteEatery(eNum);
    }

    @Override
    public Eatery getEatery(int eNum) {
        return sessionTemplate
                .getMapper(EateryMapper.class).getEatery(eNum);
    }

    @Override
    public List<Eatery> getEateryCategory(String category) {
        return sessionTemplate
                .getMapper(EateryMapper.class).getEateryCategory(category);
    }

    @Override
    public int getCategoryCount(String category) {
        return sessionTemplate
                .getMapper(EateryMapper.class).getCategoryCount(category);
    }
}
